package com.foreknow.demo13;

import java.util.*;

public class MapDemo1 {
    public static void main(String[] args) {
        List<Map<String,Person>> list = new ArrayList<>();
        Person p1 = new Person();
        p1.setName("fender");
        Person p2 = new Person();
        p2.setName("gibson");
        Person p3 = new Person();
        p3.setName("yamaha");
        Person p4 = new Person();
        p4.setName("boss");
        Map<String,Person> map1 = new HashMap<>();
        map1.put("p1",p1);
        map1.put("p2",p2);
        Map<String,Person> map2 = new HashMap<>();
        map2.put("p3",p3);
        map2.put("p4",p4);
        //将Map添加到List中
        list.add(map1);
        list.add(map2);

        //遍历List集合
        for (Map<String,Person> map :list) {
           Set<Map.Entry<String,Person>> set =  map.entrySet();
           Iterator<Map.Entry<String,Person>> it = set.iterator();
           while(it.hasNext()) {
               Map.Entry entry = it.next();
               String k = (String) entry.getKey();
               Person p = (Person) entry.getValue();
               System.out.println("key值:"+k+"名字："+p.getName());
           }
        }



    }
}
